import { useEffect, useRef } from 'react';

const DEFAULT_OPTIONS = {
  restoreOnUnmount: false, // 恢复页面标题
};

const useTitle = (title, options) => {
  if (options === void 0) {
    options = DEFAULT_OPTIONS;
  }

  const titleRef = useRef(document.title);
  useEffect(() => {
    document.title = title;

    return () => {
      if (options?.restoreOnUnmount) {
        document.title = titleRef.current;
      }
    };
  }, []);

  return;
};

export default useTitle;
